<template>
<div>
  欢迎您!{{username}}老师
  <p><font style="color: cyan">学生信息录用</font></p>
  <p>学生名字<input type="text" v-model="from.name"></p>
  <p>年龄<input type="text" v-model="from.age"></p>
  <button @click="add">提交</button>
  <p>此老师底下的学生有：</p>
  <ul>
    <li v-for="i in student">{{i.name}}<button @click="del(i.id)">删除</button></li>
  </ul>
</div>
</template>

<script>
export default {
  name: "student",
  data(){
    return{
      student:[],
      username:localStorage.getItem('username'),
      from:{'teacher':localStorage.getItem('userid')},
      userid:localStorage.getItem('userid')

    }
  },
  methods:{
    add(){
      this.$axios.post('users/student/',this.from)
      .then(res=>{
        if(res.data.code==200){
          alert('提交成功')
          this.get_student()
        }else {
          alert('提交失败')
        }
      })
    },
    get_student(){
      this.$axios.get('users/student/?userid='+this.userid).then(res=>{
        if(res.data.code==200){
          this.student = res.data.list
        }
      })
    },
    del(id){
      this.$axios.put('users/student/?id='+id)
      .then(res=>{

      })
    }
  },
  mounted() {
    let userid = localStorage.getItem('userid')
    if(!userid){
      alert('登录后操作')
    }else {

    }
    this.get_student()
  }

}
</script>

<style scoped>

</style>
